package com.tio.server.web.controller;

import com.tio.server.web.vo.User;
import com.zengtengpeng.annotation.EnableMQ;
import com.zengtengpeng.annotation.MQListener;
import com.zengtengpeng.annotation.MQPublish;
import lombok.extern.log4j.Log4j2;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Log4j2
@Controller
@RequestMapping("/mq")
public class RedissonMqController {

    @Autowired
    private RedissonClient redissonClient;

    @RequestMapping("/testMq1")
    public @ResponseBody User testMq1() {
        RTopic testMq = redissonClient.getTopic("testMq");
        User user = new User();
        user.setName("admin");
        user.setAge(10);
        testMq.publish(user);
        return user;
    }

    @RequestMapping("/testMq2")
    @MQPublish(name = "testMq")
    public @ResponseBody User testMq2() {
        User user = new User();
        user.setName("admin");
        user.setAge(30);
        return user;
    }

    @MQListener(name = "testMq")
    public void test1(CharSequence charSequence, User o, Object object) {
        log.info("charSequence={}", charSequence);
        log.info("收到消息: {}", o);
    }

}
